<?php

namespace App\Http\Controllers\SystemManager;

use App\Helpers\ResponseData;
use App\Http\Controllers\Controller;
use App\Models\HoursPrice;
use Illuminate\Http\Request;

class HourPriceController extends Controller
{
    use ResponseData;
    public function list(HoursPrice $hoursPrice,Request $request){
        $name = $request->input('name', '');
        $size = $request->input('size',10);
        $data = $hoursPrice->when($name,function($query) use($name){
            return $query->where('number', 'like','%'.$name.'%');
        })->orderBy('id','desc')->paginate($size);
        return $this->success($data);
    }
    public function store(HoursPrice $hoursPrice,Request $request){
        $data = $request->all();
        $hoursPrice->fill($data);
        $hoursPrice->save();
        return $this->success('保存成功');
    }
    public function edit(HoursPrice $hoursPrice,Request $request){
        $data = $hoursPrice->find($request->id);
        return $this->success($data);
    }
    public function update(HoursPrice $hoursPrice,Request $request){
        $data = $hoursPrice->find($request->id);
        $data->update($request->all());
        return $this->success('修改成功');
    }
    public function destory(HoursPrice $hoursPrice,Request $request){
        $data = $hoursPrice->find($request->id);
        $data->delete();
    }
}
